import { emptyData } from '../../../../../Classes/emptyData';
import { ObjectOnlyPushSet } from '../../../../ObjectOnlyPushSet_operate';
import {
  diff_prop,
  keyWorld_compared_type,
} from '../../../Classes/cla_diff_prop';
import { compare_linkObj } from '../Classes/cla_compare_linkObj';
import { compare_more_same } from '../Classes/cla_compare_more_same';
import { compare_more_same_return } from '../Classes/cla_compare_more_same_return';
import {
  deepth_diff_type,
  typ_key_goals_compare_type,
} from '../Classes/cla_deepth_diff_type';

export function seek_for_more_same(all_comp: compare_more_same) {
  let discribe_comp_arr = new emptyData();

  // 遍历 所有 比对结果
  for (const key_ind of all_comp.data) {
    // let cur_compare = <compare_linkObj>all_comp[key_ind];

    let cur_compare = all_comp[key_ind];

    // 基础 比对项
    if (cur_compare instanceof diff_prop) {
      /**
       * 逻辑 修订
       * 当 当前元素 比对结果 是 staitc 直接 退出 不在 后续 比对
       * 贪心
       */
      if (cur_compare._$223_compare_type == keyWorld_compared_type.static) {
        return new compare_more_same_return(
          keyWorld_compared_type.static,
          key_ind,
          0
        );
      }
    }

    if (
      cur_compare instanceof diff_prop ||
      cur_compare instanceof compare_linkObj ||
      cur_compare instanceof compare_more_same
    ) {
      ObjectOnlyPushSet(
        discribe_comp_arr,
        key_ind,
        new deepth_diff_type(cur_compare)
      );
    }
  }

  return get_max_goals_deepth_diff_type(discribe_comp_arr);
}

function get_max_goals_deepth_diff_type(emptyDate_deepth_diff: emptyData) {
  let cur_describe: typ_key_goals_compare_type;

  let cur_same_ind: string | number;

  let max_goals: number | undefined = undefined;

  /**
   * 初始化 最大 分数 信息值
   * @param {typ_key_goals_compare_type} describe 类型比对 描述
   * @param {number} goals 当前 最大分数
   * @param {string | number} tb_index 索引值
   */
  let init = (
    describe: typ_key_goals_compare_type,
    tb_index: string | number,
    goals: number
  ) => {
    cur_describe = describe;
    cur_same_ind = tb_index;
    max_goals = goals;
  };

  /**
   * 单元 深度 描述
   */
  let cur_deepth_diff: deepth_diff_type;

  for (const key_ind of emptyDate_deepth_diff.data) {
    cur_deepth_diff = emptyDate_deepth_diff[key_ind];

    if (
      max_goals == undefined ||
      max_goals < cur_deepth_diff._$223_compare_goals
    ) {
      init(
        cur_deepth_diff._$223_compare_describe,
        key_ind,
        cur_deepth_diff._$223_compare_goals
      );
    }
  }

  return new compare_more_same_return(cur_describe!, cur_same_ind!, max_goals!);
}
